cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)

get_filename_component(CYG_CURRENT_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(${CYG_CURRENT_PATH}/ultis.cmake)

###########################################################
# OS type
###########################################################
if(MSVC)
    set(CYG_OS "msvc")
elseif(MINGW)
    set(CYG_OS "mingw")
elseif(APPLE)
    set(CYG_OS "mac")
elseif(UNIX)
    set(CYG_OS "linux")
elseif(ANDROID)
    set(CYG_OS "android")
endif()


###########################################################
# ARCH type
###########################################################
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(CYG_ARCH "x64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
    set(CYG_ARCH "x32")
elseif(ANDROID)
    set(CYG_ARCH "armeabi-v7a")
endif()

message(STATUS "arch : ${CYG_ARCH}")
message(STATUS "operation system is ${CMAKE_SYSTEM}")


###########################################################
# BUILD type
###########################################################
if(CMAKE_BUILD_TYPE MATCHES "Debug" OR CMAKE_BUILD_TYPE MATCHES "debug")
    set(CYG_TYPE "debug")
    set(CMAKE_DEBUG_POSTFIX "d")
else()
    set(CYG_TYPE "release")
    set(CMAKE_DEBUG_POSTFIX "")
endif()


###########################################################
# PATH config
###########################################################
set(CYG_CPP_ROOT       ${CYG_CURRENT_PATH}/../..)

set(CYG_PLT_PATH       ${CYG_OS}/${CYG_ARCH}/${CYG_TYPE})

set(CYG_INC_PATH       ${CYG_CPP_ROOT}/include/cyg/pub)
set(CYG_LIB_PATH       ${CYG_CPP_ROOT}/shadow/${CYG_PLT_PATH}/lib/cyg/pub)
set(CYG_BIN_PATH       ${CYG_CPP_ROOT}/shadow/${CYG_PLT_PATH}/bin)

set(3RD_INC_PATH       ${CYG_CPP_ROOT}/3rd-party/include)
set(3RD_LIB_PATH       ${CYG_CPP_ROOT}/3rd-party/shadow/${CYG_PLT_PATH}/lib)
set(3RD_BIN_PATH       ${CYG_CPP_ROOT}/3rd-party/shadow/${CYG_PLT_PATH}/bin)

set(QT_INC_PATH        ${CYG_CPP_ROOT}/include/qt)
set(QT_LIB_PATH        ${CYG_CPP_ROOT}/shadow/${CYG_PLT_PATH}/lib/qt)

set(CYG_NOPUB_INC_PATH ${CYG_CPP_ROOT}/include/cyg/nopub)
set(CYG_NOPUB_LIB_PATH ${CYG_CPP_ROOT}/shadow/${CYG_PLT_PATH}/lib/cyg/nopub)

# message(STATUS "CYG_LIB_PATH ${CYG_LIB_PATH}")
# message(STATUS "3RD_BIN_PATH ${3RD_BIN_PATH}")

###########################################################
# Default install path
###########################################################
set(CYG_INSTALL_PREFIX   ${CMAKE_INSTALL_PREFIX}/${CYG_OS}/${CYG_ARCH}/p3000${CMAKE_DEBUG_POSTFIX})
set(INSTALL_RUN_PATH     ${CYG_INSTALL_PREFIX}/bin)
set(INSTALL_LIB_PATH     ${CYG_INSTALL_PREFIX}/lib/cyg)
set(INSTALL_3RD_PATH     ${CYG_INSTALL_PREFIX}/lib/3rd)
set(INSTALL_CONFIG_PATH  ${CYG_INSTALL_PREFIX}/config)
set(INSTALL_SCRIPT_PATH  ${CYG_INSTALL_PREFIX}/script)
set(INSTALL_DESKTOP_PATH ${CYG_INSTALL_PREFIX}/share/applications)
set(INSTALL_ICONS_PATH   ${CYG_INSTALL_PREFIX}/share)
set(INSTALL_RES_PATH     ${CYG_INSTALL_PREFIX}/res)
set(INSTALL_DOC_PATH     ${CYG_INSTALL_PREFIX}/doc)
set(INSTALL_OTHER_PATH   ${CYG_INSTALL_PREFIX}/other)

###########################################################
# Default include path
###########################################################
include_directories(
    ${CYG_CPP_ROOT}
    ${CYG_INC_PATH}
    ${3RD_INC_PATH}
    ${3RD_INC_PATH}/common)


###########################################################
# Default link path
###########################################################
link_directories(
    ${CYG_LIB_PATH}
    ${3RD_LIB_PATH})


###########################################################
# Default compile flags
###########################################################
if(WIN32)
    add_definitions(
        -wd"4819"
        )
else()
    add_definitions(
        -fPIC
        -std=c++11
        -fvisibility=hidden
        -Wno-deprecated-declarations
        )
endif()

###########################################################
# Default link flags
###########################################################
if(WIN32)
    set(CMAKE_EXE_LINKER_FLAGS    "${CMAKE_EXE_LINKER_FLAGS}    /ignore:4099")
    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /ignore:4099")
else()
    link_libraries(
        -Wl,-rpath=../lib/cyg
        -Wl,-rpath=../lib/3rd
        )
endif()
